package com.wealth.commodity.web.controller;

import iaas.utils.ResultObject;

import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wealth.commodity.entity.Goods;
import com.wealth.commodity.enums.GoodsStatusEnum;
import com.wealth.commodity.service.IGoodsService;
import com.wealth.system.web.controller.BaseController;


/**
 * @author xf
 *	特价商品
 */
@Controller
@RequestMapping(value="/cheapGoogs")
public class CheapGoodsController extends BaseController{
	
	
	Logger logger = Logger.getLogger(CheapGoodsController.class);
	@Autowired
	private IGoodsService goodsService;
	

	//特价商品首页
	@RequestMapping(value="/index")
	public String index(Model model){
		try {
			
			// 0 起始查询ID  1 是否特价标志  
			List<Goods> goodslist=goodsService.findCheapGoods(0L, 1, GoodsStatusEnum.UP.getValue());
			model.addAttribute("goodslist", goodslist);
			
			return "cheap/index";
		} catch (Exception e) {
			logger.error("特价商品列表错误", e);
			return "system/500";
		}
	}
	
	
	//特价商品加载更多
	@RequestMapping(value="/more",method=RequestMethod.POST)
	@ResponseBody
	public ResultObject more(Long maxId) {
		try{
			//   1 是否特价标志  
			List<Goods> goods=goodsService.findCheapGoods(maxId, 1, GoodsStatusEnum.UP.getValue());
			return new ResultObject("000", "加载成功", goods);
			
		}catch(Exception e){
			return new ResultObject("999", "加载错误", "");
		}
	}
	
	
	
	
	
}
